/*
 * $Header: /opt/javacvs/bk/src/main/java/com/uusee/framework/util/query/Filter.java,v 1.1 2009/04/02 10:08:52 wangrui Exp $
 * $Revision: 1.1 $
 * $Date: 2009/04/02 10:08:52 $
 * ============================================================================
 *
 * Copyright (c) 2007 Beijing uusee Tech CO.,  All rights reserved.
 *
 * ============================================================================
 */
package com.uusee.framework.util.query;

import java.util.Collection;
import java.util.Map;

/**
 * 
 * @author wangrui
 * 
 */
public final class Filter {
	public static final int ALL_EQ = 0;
	public static final int ID_EQ = 1;
	public static final int EQ = 2;
	public static final int NE = 3;
	public static final int GE = 4;
	public static final int GT = 5;
	public static final int LE = 6;
	public static final int LT = 7;
	public static final int EQ_PROPERTY = 8;
	public static final int NE_PROPERTY = 9;
	public static final int GE_PROPERTY = 10;
	public static final int GT_PROPERTY = 11;
	public static final int LE_PROPERTY = 12;
	public static final int LT_PROPERTY = 13;
	public static final int LIKE = 14;
	public static final int LEFT_LIKE = 15;
	public static final int RIGHT_LIKE = 16;
	public static final int IS_EMPTY=17;
	public static final int IS_NOT_EMPTY=18;
	public static final int IS_NULL=19;
	public static final int IS_NOT_NULL=20;
	public static final int BETWEEN = 21;
	public static final int IN = 22;
	
	public static final int AND = 23;
	public static final int OR = 24;
	public static final int NOT = 25;
	
	public static final int SQL_RESTRICTION = 0;
	
	//conjunction()
	//disjunction()
	//naturalId()
	//sizeEq(String propertyName, int size)
	//sizeGe(String propertyName, int size)
	//sizeGt(String propertyName, int size)
	//sizeLe(String propertyName, int size)
	//sizeLt(String propertyName, int size)
	//sizeNe(String propertyName, int size)
	//sqlRestriction(String sql)
	//sqlRestriction(String sql, Object[] values, Type[] types)
	//sqlRestriction(String sql, Object value, Type type)

	private final Map propertyNameValues;
	private final String propertyName;
	private final String otherPropertyName;
	private final Object value;
	private final Object lowValue;
	private final Object highValue;
	private final Collection collectionValues;
	private final Object[] objectValues;
	//private final String sql;
	//private final Type[] types;
	//private final Type[] type;
	private final Filter logicCondition;
	private final Filter otherLogicCondition;
	private final int operator;
    

	public Filter(Object value) {
		this.value = value;
		this.operator = ID_EQ;
		
		this.propertyNameValues = null;
		this.propertyName = null;
		this.lowValue = null;
		this.highValue = null;
		this.otherPropertyName = null;
		this.collectionValues = null;
		this.objectValues = null;
		this.logicCondition = null;
		this.otherLogicCondition = null;
	}
	
	public Filter(Map propertyNameValues) {
		this.propertyNameValues = propertyNameValues;
		this.operator = ALL_EQ;
		
		this.propertyName = null;
		this.value = null;
		this.lowValue = null;
		this.highValue = null;
		this.otherPropertyName = null;
		this.collectionValues = null;
		this.objectValues = null;
		this.logicCondition = null;
		this.otherLogicCondition = null;
	}
	
	public Filter(String propertyName, int operator){
		this.propertyName = propertyName;
		this.operator = operator;
		
		this.propertyNameValues = null;
		this.value = null;
		this.lowValue = null;
		this.highValue = null;
		this.otherPropertyName = null;
		this.collectionValues = null;
		this.objectValues = null;
		this.logicCondition = null;
		this.otherLogicCondition = null;
	}

	public Filter(String propertyName, Object value, int operator) {
		this.propertyName = propertyName;
		this.value = value;
		this.operator = operator;
		
		if (value instanceof String) {
			this.otherPropertyName = (String)value;
		} else {
			this.otherPropertyName = null;
		}
		
		if (value instanceof Collection) {
			this.collectionValues = (Collection)value;
		} else {
			this.collectionValues = null;
		}
		
		this.propertyNameValues = null;
		this.lowValue = null;
		this.highValue = null;
		this.objectValues = null;
		this.logicCondition = null;
		this.otherLogicCondition = null;
	}
	
	public Filter(String propertyName, Object[] objectValues, int operator) {
		this.propertyName = propertyName;
		this.objectValues = objectValues;
		this.operator = operator;
		
		this.propertyNameValues = null;
		this.value = null;
		this.lowValue = null;
		this.highValue = null;
		this.otherPropertyName = null;
		this.collectionValues = null;
		this.logicCondition = null;
		this.otherLogicCondition = null;
	}
	
	public Filter(String propertyName, Object lowValue, Object highValue, int operator) {
		this.propertyName = propertyName;
		this.lowValue = lowValue;
		this.highValue = highValue;
		this.operator = operator;
		
		this.propertyNameValues = null;
		this.value = null;
		this.otherPropertyName = null;
		this.collectionValues = null;
		this.objectValues = null;
		this.logicCondition = null;
		this.otherLogicCondition = null;
	}
	
	public Filter(Filter logicCondition, Filter otherLogicCondition, int operator) {
		this.logicCondition = logicCondition;
		this.otherLogicCondition = otherLogicCondition;
		this.operator = operator;
		
		this.propertyNameValues = null;
		this.propertyName = null;
		this.value = null;
		this.lowValue = null;
		this.highValue = null;
		this.otherPropertyName = null;
		this.collectionValues = null;
		this.objectValues = null;

	}

	
	public Map getPropertyNameValues() {
		return propertyNameValues;
	}

	public String getPropertyName() {
		return propertyName;
	}

	public String getOtherPropertyName() {
		return otherPropertyName;
	}

	public Object getValue() {
		return value;
	}

	public Object getLowValue() {
		return lowValue;
	}

	public Object getHighValue() {
		return highValue;
	}

	public Collection getCollectionValues() {
		return collectionValues;
	}

	public Object[] getObjectValues() {
		return objectValues;
	}

	public Filter getLogicCondition() {
		return logicCondition;
	}

	public Filter getOtherLogicCondition() {
		return otherLogicCondition;
	}

	public int getOperator() {
		return operator;
	}

	
	
}
